﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Device
{
    public partial class ResetPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Linker();
            Label1.Text = Util.UserName();
            Image1.ImageUrl = "../WebForm1.aspx";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string Str1 = "校验码错误！请重新输入！";
            string Str2 = "请获取验证码！";
            var checkCode = TextBox3.Text.Trim();
            RegionCode.Result result = RegionCode.CheckCodeSame(checkCode);
            switch (result)
            {
                case RegionCode.Result.Fail:
                    Util.AlertString(Str1, Response);
                    break;
                case RegionCode.Result.Success:
                    alterpasswork();
                    MultiView1.ActiveViewIndex = 1;
                    break;
                case RegionCode.Result.CodeNull:
                    Util.AlertString(Str2, Response);
                    break;
            }

        }

        //是否可以链接
        void Linker()
        {
            DateTime time = DateTime.Now;
            Util.Result result = Util.OverTime(time);
            switch (result)
            {
                case Util.Result.Success:
                    break;
                case Util.Result.OverTime:
                    Response.Redirect("OverTime.aspx");
                    break;
            }
        }





        //大问题，要查询用户的id然后再修改密码

        //修改密码
        void alterpasswork()
        {
            var  id =Convert.ToInt32 (Util.UserId());
            var password_sha = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text.Trim(), "SHA1");
            Model1Container db = new Model1Container();
            EquipmentMaster cmn = db.EquipmentMaster集.FirstOrDefault(cc => cc.id == id);
            cmn.password = password_sha;
            EquipmentMaster update = db.EquipmentMaster集.FirstOrDefault(cc => cc.id == id);
            db.SaveChanges();
        }
    }
}